package com.zwf.mapper;

import com.github.pagehelper.Page;
import com.zwf.dto.OrdersPageQueryDTO;
import com.zwf.entity.Orders;
import com.zwf.vo.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @Author zwf
 * @date 2024/2/12 9:37
 */
@Mapper
public interface OrderMapper {

    /**
     * 订单表中插入数据
     * @param orders
     */
    void add(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据id查询订单信息
     * @param id
     * @return
     */
    @Select("select * from orders where id=#{id}")
    @SelectKey(statement = {}, keyProperty = "id", before = false, resultType = Long.class)
    Orders getById(Long id);

    /**
     * PageResult pageResult=new PageResult();
     *         pageResult.setTotal(pageResult.getTotal());
     *         pageResult.setRecords(pageResult.getRecords());
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 动态统计
     * @param orders
     * @return
     */
    Integer count(Orders orders);

    /**
     * 查询超时订单
     * @param pendingPayment
     * @param time
     * @return
     */
    @Select("select * from orders where status=#{pendingPayment} and order_time < #{time}")
    List<Orders> findOutTimeByStatus(Integer pendingPayment, LocalDateTime time);

    /**
     * 动态查询当天营业额
     * @param map
     * @return
     */
    Double sumTurnoverByMap(Map map);

    /**
     * 动态查询某时间段订单总数
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
